


//
//  DemandTheHallContentHeadCell.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/16.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "DemandTheHallContentHeadCell.h"
#import "HomeModel.h"
@interface DemandTheHallContentHeadCell()
@property (weak, nonatomic) IBOutlet UILabel *generalizeL;
@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UILabel *industry;
@property (weak, nonatomic) IBOutlet UILabel *placeL;
@property (weak, nonatomic) IBOutlet UILabel *creatTimeL;
@property (weak, nonatomic) IBOutlet UIView *animationView;
@property (weak, nonatomic) IBOutlet UILabel *percentL;
@property (weak, nonatomic) IBOutlet UILabel *evaluateL;
@property(nonatomic,strong) CAShapeLayer *lineLayer;
@end


@implementation DemandTheHallContentHeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.headImg.layer.masksToBounds = YES;
    self.headImg.layer.cornerRadius = 58/2;
    self.headImg.layer.borderColor  = kYuanbianColor.CGColor;
    self.headImg.layer.borderWidth  = 1;
    self.collectBtn.layer.masksToBounds = YES;
    self.collectBtn.layer.cornerRadius = 15;
    self.animationView.layer.masksToBounds = YES;
    self.animationView.layer.cornerRadius = 3;
    self.animationView.backgroundColor = kWhite;
    

}

- (void)setHomeDemandModel:(HomeModel *)homeDemandModel
{
    _homeDemandModel = homeDemandModel;
    self.collectBtn.selected = homeDemandModel.collectStatus;
    NSString *title =[NSString stringWithFormat:@"需求概述:  %@",homeDemandModel.title];
    NSMutableAttributedString *titleS = [[NSMutableAttributedString alloc] initWithString:title];
    NSRange range1 = [[titleS string] rangeOfString:@"需求概述:  "];
    [titleS addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:76/255.0 green:152/255.0 blue:57/255.0 alpha:1] range:range1];
    self.generalizeL.attributedText = titleS;
    
    NSString *industry = [NSString stringWithFormat:@"所属行业:  %@",homeDemandModel.industry];
    NSMutableAttributedString *industryS = [[NSMutableAttributedString alloc] initWithString:industry];
    NSRange range2 = [[industryS string] rangeOfString:@"所属行业:  "];
    [industryS addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:76/255.0 green:152/255.0 blue:57/255.0 alpha:1] range:range2];
    self.industry.attributedText  = industryS;
    
    NSString *place =[NSString stringWithFormat:@"合作地区:  %@",homeDemandModel.place];
    NSMutableAttributedString *placeS = [[NSMutableAttributedString alloc] initWithString:place];
    NSRange range3 = [[placeS string] rangeOfString:@"合作地区:  "];
    [placeS addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:76/255.0 green:152/255.0 blue:57/255.0 alpha:1] range:range3];
    self.placeL.attributedText = placeS;
    
    [self.headImg sd_setImageWithURL:[NSURL URLWithString:homeDemandModel.headImg] placeholderImage:[UIImage imageNamed:@"headImg"]];
    
    NSTimeInterval interval    = homeDemandModel.creattime/1000.0;
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *currentDateStr = [formatter stringFromDate: date];
    NSString *time =[NSString stringWithFormat:@"截止时间:  %@",currentDateStr];
    NSMutableAttributedString *timeS = [[NSMutableAttributedString alloc] initWithString:time];
    NSRange range4 = [[timeS string] rangeOfString:@"截止时间:  "];
    [timeS addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:76/255.0 green:152/255.0 blue:57/255.0 alpha:1] range:range4];
    self.creatTimeL.attributedText = timeS;
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0, 3)];
    path.lineCapStyle = kCGLineCapRound;
    [path addLineToPoint:CGPointMake(homeDemandModel.believe*53, 3)];
    self.percentL.text = [NSString stringWithFormat:@"%@%%",[self formatFloat:homeDemandModel.believe*100]];
    path.lineWidth = 6;
    self.lineLayer = [CAShapeLayer layer];
    self.lineLayer.lineWidth = 6;
    self.lineLayer.lineCap = kCALineCapRound;
    self.lineLayer.strokeColor = [UIColor colorWithRed:151/255.0 green:193/255.0 blue:91/255.0 alpha:1].CGColor;
    self.lineLayer.path = path.CGPath;
    [self.animationView.layer addSublayer:self.lineLayer];
}
- (IBAction)collectBtn:(UIButton *)sender {
//    sender.selected = !sender.selected;
    if ([self.delegate respondsToSelector:@selector(demandTheHallContentHeadCell:withCollectBtn:)]) {
        [self.delegate demandTheHallContentHeadCell:self withCollectBtn:sender];
    }
}
- (NSString *)formatFloat:(float)f
{
    if (fmodf(f, 1)==0) {//如果有一位小数点
        return [NSString stringWithFormat:@"%.0f",f];
    } else if (fmodf(f*10, 1)==0) {//如果有两位小数点
        return [NSString stringWithFormat:@"%.1f",f];
    } else {
        return [NSString stringWithFormat:@"%.2f",f];
    }
}
@end
